<template>
  <div class="cart">
      <Header title="购物车" >
          <template v-slot:left>
              <span @click="$router.go(-1)">&lt;</span>
          </template>
          <template v-slot:right>
              <span>...</span>
          </template>
      </Header>
      <div class="list" v-if="gwclist.length>0">
          <div class="item" v-for="(it,index) in gwclist" :key="index">
               <div class="img">
        <img :src="it.pic" alt />
      </div>
      <div class="text">
        <div class="title">商品：{{it.title}}</div>
        <div class="ys">已售：{{it.ys}}</div>
        <div class="dj">单价：{{it.dj}}</div>
            <div class="btn">
            <span @click="remcount(it.id)">-</span>
            {{it.count}}
            <span @click="addcount(it.id)">+</span>
            </div>
      </div>
          </div>
      </div>
      <div class="img" v-else>
          <img src="../../assets/img/没有更多.png" alt="">
          <div>还没有商品，快去逛逛吧!!</div>
      </div>
      <div class="footer">
          <div class="zsl">总数量:{{gwclist.reduce((a,b)=>{return a+b.count},0)}}件</div>
          <div class="zj">总价:{{gwclist.reduce((a,b)=>{return a+b.count*b.dj},0)}}元</div>
          <div class="js">结算</div>
      </div>
  </div>
</template>

<script>
import { mapState, mapMutations, mapActions } from "vuex";
import { MessageBox } from "mint-ui";
import "mint-ui/lib/style.css";
export default {
 computed: {
    ...mapState(["gwclist"])
  },
  methods: {
      ...mapMutations(['remcount','addcount'])
  },
}
</script>

<style lang="scss">
.img{
    text-align: center;
    margin-top: 50px;
}
.header{
    width: 100%;
    height: 40px;
    display: flex;
    background: #eee;
    div{
    flex: 1;
    text-align: center;
    line-height: 40px;
    }
}
.footer{
    width: 100%;
    height: 40px;
    line-height: 40px;
    display: flex;
    position: fixed;
    left: 0;
    bottom: 0;
    text-align: center;
    .zsl{
        color:aliceblue;
        width: 30%;
        background: mediumaquamarine;
        border-right: 1px solid red;
    }
    .zj{
        color:aliceblue;
        width: 30%;
        background: mediumaquamarine;
    }
    .js{
        color:aliceblue;
        width: 40%;
        background: red;
    }
}
</style>